import { defineStore, createPinia } from 'pinia';
interface FormData {
  startTime?: string;
  endTime?: string;
  roletype?: string;
  txtKey?: string;
  xzq?: string;
  fooler?: any;
  category?: string;
  currentTitle?: string;
  taskid?: string;
  hyzt2:string;
  villagedm:string;
  taskname:string;
  village:string;
  jsrysstd:string;
}
const pinia = createPinia();


export const useCheckStore = defineStore('check', {
  state: (): { formData: FormData } => ({
    formData: {},
  }),
  actions: {
    setFormData(data: FormData) {
      this.formData = { ...this.formData, ...data };
    },
    clearFormData() {
      this.formData = {};
    },
    setData(data: any) {
      this.formData = data;
    },
  },
});

export const useTitleStore = defineStore('title', {
  state: () => ({
    currentTitle: '房屋记录',
  }),
  actions: {
    setTitle(newTitle: string) {
      this.currentTitle = newTitle;
      document.title = newTitle;
    },
  },
});
export const useFormStore = defineStore('form', {
  state: () => ({
    formData: {} as FormData,
  }),
  actions: {
    saveToLocal() {
      localStorage.setItem('formData', JSON.stringify(this.formData));
    },
    loadFromLocal() {
      const data = localStorage.getItem('formData');
      if (data) this.formData = JSON.parse(data);
    },
  },
  persist: true, // 启用插件持久化
});
